package com.ve.view.editor.span;

import android.graphics.Paint;

import java.util.ArrayList;
import java.util.List;

import static com.ve.view.editor.span.SpanType.NORMAL;

public class TextSpanData {


    private List<SpanNode> spanNodes;

    public TextSpanData() {
        spanNodes = new ArrayList<>();
        addSpan(0, NORMAL);
    }

    public List<SpanNode> getSpanNodes() {
        return spanNodes;
    }

    public void addSpan(int length, SpanType type) {
        if (type == null) {
            type = NORMAL;
        }
        spanNodes.add(new SpanNode( type,length));

    }


    public void clear() {
        spanNodes.clear();
        addSpan(0, NORMAL);
    }


    public SpanSeeker getNewSeeker(Paint paint) {
        return new SpanSeeker(this, paint);
    }


    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(getClass().getSimpleName() + "(" + spanNodes.size() + ")" + "{\n");
        for (SpanNode spanNode : spanNodes) {
            stringBuilder.append(spanNode);
        }

        return stringBuilder.append("\n}\n").toString();
    }
}
